package com.xiaoma.bingox.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dexcoder.commons.pager.Pager;
import com.dexcoder.dal.JdbcDao;
import com.dexcoder.dal.build.Criteria;
import com.dexcoder.dal.spring.page.PageControl;
import com.xiaoma.bingox.entity.Role;
import com.xiaoma.bingox.entity.RoleResource;

@Service
public class RoleService {

    @Autowired
    private JdbcDao jdbcDao;
    
    public Pager findAll(int currentPage, int itemsPerPage) {
        PageControl.performPage(currentPage, itemsPerPage);
        jdbcDao.queryList(Role.class);
        return PageControl.getPager();
        
    }
    
    public void save(Role role) {
        jdbcDao.save(role);
    }
    
    public void delete(int id) {
        jdbcDao.delete(Role.class, id);
    }
    
    public void update(Role role) {
        jdbcDao.update(role);
    }
    
    public void save(RoleResource roleResource) {
        jdbcDao.save(roleResource);
    }
    
    public void delete(RoleResource roleResource) {
        jdbcDao.delete(roleResource);
    }
    
    public List<Role> findSelectDatas() {
        Criteria c = Criteria.select(Role.class).include("id","role");
        return jdbcDao.queryList(c);
    }
}
